<template>
    <div style="height:100%;">
        <!--v-if="createUser.role.roleKey == 'admin' || createUser.role.roleKey == 'ptjxy'"-->
        <div class="dashboard-editor-container">
            <!--v-if="createUser.role.roleKey == 'admin' || createUser.role.roleKey == 'ptjxy'"|| createUser.role.roleKey == 'bdjgjxy'|| createUser.role.roleKey == 'ptjl'-->

            <el-row :gutter="40" class="panel-group">
                <el-col :xs="12" :sm="12" :lg="5" class="card-panel-col">
                    <div class="card-panel">
                        <div class="card-title">上报案件</div>
                        <p class="card-count"><span>{{reportCount}}</span></p>
                    </div>
                </el-col>
                <el-col :xs="12" :sm="12" :lg="5" class="card-panel-col" style="padding-left: 0;">
                    <div class="card-panel">
                        <div class="card-title">已转办案件</div>
                        <p class="card-count"><span>{{alreadyZb}}</span></p>
                    </div>
                </el-col>
                <el-col :xs="12" :sm="12" :lg="5" class="card-panel-col" style="padding-left: 0;">
                    <div class="card-panel">
                        <div class="card-title">已结案案件</div>
                        <p class="card-count"><span>{{alreadyJa}}</span></p>
                    </div>
                </el-col>
                <el-col :xs="12" :sm="12" :lg="5" class="card-panel-col" style="padding-left: 0;">
                    <div class="card-panel">
                        <div class="card-title">回退案件</div>
                        <p class="card-count"><span>{{backoffCount}}</span></p>
                    </div>
                </el-col>
                <el-col :xs="12" :sm="12" :lg="4" class="card-panel-col" style="padding-left: 0;">
                    <div class="card-panel">
                        <div class="card-title">其他</div>
                        <p class="card-count"><span>{{otherCount}}</span></p>
                    </div>
                </el-col>
            </el-row>

            <el-row style="background:#fff;padding:0.2rem 0.2rem 0;margin-bottom:0.1875rem;">
                <div id="ontimeChart"></div>
            </el-row>

            <el-row :gutter="16">
                <el-col :xs="36" :sm="36" :lg="12">
                    <div class="chart-wrapper">
                        <!--延期、缓办、挂起案件在全部案件中占比统计图-->
                        <pie-chart/>
                    </div>
                </el-col>
                <el-col :xs="36" :sm="36" :lg="12">
                    <div class="chart-wrapper">
                        <pie-charttwo/>
                    </div>
                </el-col>
            </el-row>

        </div>

        <!--<div class="dashboard-editor-container" v-if="createUser.role.roleKey == 'ptjl'">-->
            <!--<el-row :gutter="40" class="panel-group">-->
                <!--<el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">-->
                    <!--<div class="card-panel">-->
                        <!--<div class="card-title">全部案件</div>-->
                        <!--<p class="card-count"><span>{{allCount}}</span></p>-->
                    <!--</div>-->
                <!--</el-col>-->
                <!--<el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">-->
                    <!--<div class="card-panel">-->
                        <!--<div class="card-title">待核查案件</div>-->
                        <!--<p class="card-count"><span>{{tobeViewedCount}}</span></p>-->
                    <!--</div>-->
                <!--</el-col>-->
                <!--<el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">-->
                    <!--<div class="card-panel">-->
                        <!--<div class="card-title">已核查案件</div>-->
                        <!--<p class="card-count"><span>{{verifiedCount}}</span></p>-->
                    <!--</div>-->
                <!--</el-col>-->
                <!--<el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">-->
                    <!--<div class="card-panel">-->
                        <!--<div class="card-title">已结案案件</div>-->
                        <!--<p class="card-count"><span>{{jaCount}}</span></p>-->
                    <!--</div>-->
                <!--</el-col>-->
            <!--</el-row>-->

            <!--<el-row style="background:#fff;padding:16px 16px 0;margin-bottom:15px;">-->
                <!--<el-col :xs="12" :sm="12" :lg="colSpan" v-show="colShowOne">-->
                    <!--<div id="JlChart1" style="height:300px;"></div>-->
                <!--</el-col>-->
                <!--<el-col :xs="12" :sm="12" :lg="colSpan" v-show="colShowTwo">-->
                    <!--<div id="JlChart2" style="height:300px;"></div>-->
                <!--</el-col>-->
                <!--<el-col :xs="12" :sm="12" :lg="colSpan" v-show="colShowThree">-->
                    <!--<div id="JlChart3" style="height:300px;"></div>-->
                <!--</el-col>-->
            <!--</el-row>-->

            <!--<el-row style="background:#fff;padding:16px 16px 0;margin-bottom:15px;">-->
                <!--<bar-charttwo/>-->
            <!--</el-row>-->
        <!--</div>-->

        <!--<div class="dashboard-editor-container" v-if="createUser.role.roleKey == 'bdjgjxy'">-->
            <!--<el-row :gutter="40" class="panel-group">-->
                <!--<el-col :xs="12" :sm="12" :lg="5" class="card-panel-col">-->
                    <!--<div class="card-panel">-->
                        <!--<div class="card-title">案件总量</div>-->
                        <!--<p class="card-count"><span>{{jgallCount}}</span>件</p>-->
                    <!--</div>-->
                <!--</el-col>-->
                <!--<el-col :xs="12" :sm="12" :lg="5" class="card-panel-col"  style="padding-left: 0;">-->
                    <!--<div class="card-panel">-->
                        <!--<div class="card-title">待处置案件</div>-->
                        <!--<p class="card-count"><span>{{dczCount}}</span></p>-->
                    <!--</div>-->
                <!--</el-col>-->
                <!--<el-col :xs="12" :sm="12" :lg="5" class="card-panel-col"  style="padding-left: 0;">-->
                    <!--<div class="card-panel">-->
                        <!--<div class="card-title">待核查案件</div>-->
                        <!--<p class="card-count"><span>{{dbdjghcCount}}</span></p>-->
                    <!--</div>-->
                <!--</el-col>-->
                <!--<el-col :xs="12" :sm="12" :lg="5" class="card-panel-col"  style="padding-left: 0;">-->
                    <!--<div class="card-panel">-->
                        <!--<div class="card-title">已结案案件</div>-->
                        <!--<p class="card-count"><span>{{jgjaCount}}</span></p>-->
                    <!--</div>-->
                <!--</el-col>-->
                <!--<el-col :xs="12" :sm="12" :lg="4" class="card-panel-col"  style="padding-left: 0;">-->
                    <!--<div class="card-panel">-->
                        <!--<div class="card-title">回退案件</div>-->
                        <!--<p class="card-count"><span>{{jghtCount}}</span></p>-->
                    <!--</div>-->
                <!--</el-col>-->
            <!--</el-row>-->
        <!--</div>-->
    </div>
</template>

<script>
    import Cookies from 'js-cookie'
    import { getGroupCountOfJl, getGroupTimeCount, getGroupCount, getThreeGroup, getGroupIndustryTypeByDept } from '@/api/case/statisticalChart'
    import echarts from 'echarts'
    require('echarts/theme/macarons') // echarts theme
    import resize from './dashboard/mixins/resize'
    //接线员-----延期、缓办、挂起案件在全部案件中占比统计图
    import PieChart from './dashboard/PieChart'
    //接线员-----各个部门案件数量及占比
    import PieCharttwo from './dashboard/PieChartTwo'
    //获取监理-----案件总量（负责监管且标段机构受理案件）、待监理核查案件、已核查案件、已结案案件
    import BarChart from './dashboard/BarChart'
    //获取监理----标段机构案件数量前五标段机构统计
    import BarCharttwo from './dashboard/BarChartTwo'

    export default {
        mixins: [resize],
        name: 'Index',
        components: {
            PieChart,
            PieCharttwo,
            BarChart,
            BarCharttwo
        },
        data() {
            return {
                // 登录的用户信息
                createUser: JSON.parse(localStorage.getItem('userInfo')),
                //----平台接线员-------//
                //上报案件数量
                reportCount:0,
                //已转办案件数量
                alreadyZb:0,
                //已结案数量
                alreadyJa:0,
                //回退案件
                backoffCount:0,
                //其他
                otherCount:0,
                //整点实时上报案件（8-20点折线图）
                OntimeChart: null,
                OntimeData:[],
                OntimeXaxis:[],
                //-----监理------//
                //全部案件
                allCount:0,
                //待监理审核案件
                tobeViewedCount:0,
                //已核查案件
                verifiedCount:0,
                //已	结案案件
                jaCount:0,
                //------机构-----//
                //案件总量
                jgallCount:0,
                //待处置案件
                dczCount:0,
                //待标段机构核查案件
                dbdjghcCount:0,
                //已结案案件
                jgjaCount:0,
                //回退案件
                jghtCount:0,
                colSpan:24,
                colShowOne:false,
                colShowTwo:false,
                colShowThree:false,
            }
        },
        mounted(){
            // 获取接线员----上报案件、已转办案件、已结案案件、其他---总数
            this.getGroupCount();
            //获取接线员-----整点实时上报案件（8-20点折线图）
            if(this.createUser.role.roleKey === 'admin' || this.createUser.role.roleKey === 'ptjxy'){
                this.getGroupTimeCount();
            }
            //获取监理-----案件总量（负责监管且标段机构受理案件）、待监理核查案件、已核查案件、已结案案件
            this.getGroupCountOfJl();
            //获取标段机构案件统计
            this.getThreeGroup();
            //负责监管行业类别案件统计
            this.getGroupIndustryTypeByDept();
        },
        methods: {
            //负责监管行业类别案件统计
            getGroupIndustryTypeByDept(){
                getGroupIndustryTypeByDept().then(
                    (res) => {
                        if(res.msg == ''){
                            return;
                        }
                        let data = JSON.parse(res.msg);
                        let xAxis={}, dataobj={};
                        if(data.length === 0){
                            this.colSpan=8;
                            this.colShowOne=true;
                            this.colShowTwo=true;
                            this.colShowThree=true;
                        }
                        if(data.length === 1){
                            this.colSpan=24;
                            this.colShowOne=true;
                            this.colShowTwo=false;
                            this.colShowThree=false;
                        }
                        if(data.length === 2){
                            this.colSpan=12;
                            this.colShowOne=true;
                            this.colShowTwo=true;
                            this.colShowThree=false;
                        }
                        if(data.length === 3){
                            this.colSpan=8;
                            this.colShowOne=true;
                            this.colShowTwo=true;
                            this.colShowThree=true;
                        }
                        for(let i=0;i<data.length;i++){
                            xAxis['arr'+i] = [];
                            dataobj['arr'+i] = [];
                            if(data[i].datas.length > 0){
                                for(let j=0;j<data[i].datas.length;j++){
                                    xAxis['arr'+i].push(data[i].datas[j].name);
                                }
                                dataobj['arr'+i]=data[i].datas;
                            }
                            this.$nextTick(() => {
                                this.initJLChart('JlChart'+(i+1), data[i].dept_name, xAxis['arr'+i], dataobj['arr'+i]);
                            })
                        }
                    }
                ).catch((error) => {
                    console.log(error, 'getGroupIndustryTypeByDept');
                })
            },
            initJLChart(id, title, xAxis, data) {
                if (document.getElementById(id)) {
                    this.chart = echarts.init(document.getElementById(id), 'macarons');
                } else {
                    return
                }
                this.chart.setOption({
                    title: {
                        text: title,
                        textStyle:{
                            color: '#6b6b6b',
                            fontSize: 15,
                            fontWeight: 'normal'
                        },
                        left: 'center'
                    },
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: { // 坐标轴指示器，坐标轴触发有效
                            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
                        }
                    },
                    grid: {
                        top: 30,
                        left: '2%',
                        right: '2%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: [{
                        type: 'category',
                        data: xAxis,
                        axisTick: {
                            alignWithLabel: true
                        }
                    }],
                    yAxis: [{
                        type: 'value',
                        axisTick: {
                            show: false
                        }
                    }],
                    series: {
                        data: data,
                        type: 'bar',
                        showBackground: true,
                        barWidth:'16%'
                    }
                })
            },
            //获取标段机构案件统计
            getThreeGroup(){
                getThreeGroup().then(
                    (res) => {
                        //案件总量
                        this.jgallCount=res.data.ysl;
                        //待处置案件
                        this.dczCount=res.data.dcz;
                        //待标段机构核查案件
                        this.dbdjghcCount=res.data.jgsh;
                        //已结案案件
                        this.jgjaCount=res.data.yja;
                        //回退案件
                        this.jghtCount=res.data.yht;
                    }
                ).catch((error) => {
                    console.log(error, 'getThreeGroup');
                })
            },
            //获取监理-----案件总量（负责监管且标段机构受理案件）、待监理核查案件、已核查案件、已结案案件
            getGroupCountOfJl(){
                getGroupCountOfJl().then(
                    (res) => {
                        let data = res.data;
                        this.allCount = data.count;
                        this.tobeViewedCount = data.jldsh;
                        this.verifiedCount = data.jlysh;
                        this.jaCount = data.yja;
                    }
                ).catch((error) =>{
                    console.log(error, 'getGroupCountOfJl');
                })
            },
            //获取接线员-----整点实时上报案件（8-20点折线图）
            getGroupTimeCount(){
                this.OntimeChart = null;
                getGroupTimeCount().then(
                    (res) => {
                        let data = res.data;
                        for(let i=0;i<data.length;i++){
                            this.OntimeXaxis.push(data[i].name);
                            this.OntimeData.push(data[i].value);
                        }
                        this.$nextTick(() => {
                            this.initTimeChart();
                        })
                    }
                ).catch((error) => {
                    console.log(error, 'getGroupTimeCount');
                })
            },
            // 获取接线员----上报案件、已转办案件、已结案案件、其他---总数
            getGroupCount(){
                getGroupCount().then(
                    (res) => {
                        let data = JSON.parse(res.data.array_to_json.value)[0];
                        //上报案件数量
                        this.reportCount = data.sb_count;
                        //已转办案件数量
                        this.alreadyZb = data.yzb_count;
                        //已结案数量
                        this.alreadyJa = data.yja_count;
                        //回退案件
                        this.backoffCount = data.yht_count;
                        //其他
                        this.otherCount = data.qt_count;
                    }
                ).catch((error) =>{
                    console.log(error, 'getGroupCount');
                })
            },
            initTimeChart() {
                if (document.getElementById('ontimeChart')) {
                    this.OntimeChart = echarts.init(document.getElementById('ontimeChart'), 'macarons');
                } else {
                    return
                }
                this.setOptions(this.chartData)
            },
            setOptions({} = {}) {
                this.OntimeChart.setOption({
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: { // 坐标轴指示器，坐标轴触发有效
                            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
                        }
                    },
                    title: {
                        text: '整点实时上报案件（8-20点折线图）',
                        textStyle:{
                            color: '#6b6b6b',
                            fontSize: 15,
                            fontWeight: 'normal'
                        },
                        left: 'center'
                    },
                    xAxis: {
                        data: this.OntimeXaxis,
                        type: 'category',
                    },
                    yAxis: {
                        type: 'value'
                    },
                    grid: {
                        left: 10,
                        right: 10,
                        bottom: 30,
                        top: 50,
                        containLabel: true
                    },
                    series: [{
                        data: this.OntimeData,
                        type: 'line'
                    }]
                })
            }
        }
    }
</script>

<style lang="scss" scoped>
    .dashboard-editor-container {
        width: 100%;
        height: 100%;
        padding: 0.1875rem;
        background-color: rgb(240, 242, 245);
        position: relative;
        overflow-y: auto;
        overflow-x: hidden;
        .chart-wrapper {
            background: #fff;
            padding: 0.2rem 0.2rem 0;
            /*margin-bottom: 15px;*/
        }
        .panel-group {
            /*margin-top: 18px;*/

            .card-panel-col {
                margin-bottom: 0.1875rem;
            }
            .card-panel {
                height: 1.625rem;
                cursor: pointer;
                font-size: 0.225rem;
                text-align: center;
                position: relative;
                overflow: hidden;
                color: #888;
                background: #fff;
                box-shadow: 0.05rem 0.05rem 0.5rem rgba(0, 0, 0, .05);
                border-color: rgba(0, 0, 0, .05);
                .card-title{
                    margin-top:0.325rem;
                }
                .card-count{
                    font-size: 0.2rem;
                    color: #8f8e8e;
                    span{
                        font-size: 0.45rem;
                    }
                }
                &:hover {
                    .card-panel-icon-wrapper {
                        color: #fff;
                    }

                    .icon-people {
                        background: #40c9c6;
                    }

                    .icon-message {
                        background: #36a3f7;
                    }

                    .icon-money {
                        background: #f4516c;
                    }

                    .icon-shopping {
                        background: #34bfa3
                    }
                }

                .icon-people {
                    color: #40c9c6;
                }

                .icon-message {
                    color: #36a3f7;
                }

                .icon-money {
                    color: #f4516c;
                }

                .icon-shopping {
                    color: #34bfa3
                }

                .card-panel-icon-wrapper {
                    float: left;
                    margin: 0.175rem 0 0 0.175rem;
                    padding: 0.2rem;
                    transition: all 0.38s ease-out;
                    border-radius: 0.075rem;
                }

                .card-panel-icon {
                    float: left;
                    font-size: 0.6rem;
                }
                .card-panel-description {
                    float: right;
                    font-weight: bold;
                    margin: 0.325rem;
                    margin-left: 0px;

                    .card-panel-text {
                        line-height: 0.225rem;
                        color: rgba(0, 0, 0, 0.45);
                        font-size: 0.2rem;
                        margin-bottom: 0.15rem;
                    }

                    .card-panel-num {
                        font-size: 0.25rem;
                    }
                }
            }
        }
        #ontimeChart{
            height:4.25rem;
        }
    }

    @media (max-width: 12.8rem) {
        .chart-wrapper {
            padding: 0.1rem;
        }
    }
</style>
